<?php
namespace zake\foundation\stream;

use zake\foundation\able\stream\ReadAble;
use zake\foundation\able\traits\ReadTrait;
use zake\foundation\able\traits\ResourceTrait;
use zake\helper\Console;

class ReadStream implements ReadAble
{
    use ResourceTrait,ReadTrait;


    const MODE_ONCE     = 0B00000001; // 读一次
    const MODE_PERSIST  = 0B00000010; // 按frame读取


    // 每次读取的最大长度
    const READ_MAX_LENGTH = 65535;

    // frame最大长度
    const FRAME_MAX_LENGTH = 1000000; // 1000k


    public static function create($resource)
    {
        return new static($resource);
    }


    /**
     * 构造器
     *
     * ReadStream constructor.
     * @param $resource
     */
    protected function __construct($resource)
    {
        $this->resource = $resource;
        $this->fd = (int)$resource;
    }


    public function __destruct()
    {
        Console::success("read stream __destruct");
    }

}